﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Linq.Expressions;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Derbster.Domain
{
    [ContractClass(typeof(OfficialRepositoryContracts))]
    public interface IOfficialRepository : IDisposable, IQueryable<Official>
    {
        Official Create(string name);
        Official Create(string name, string number);
        Official FindById(int officialId);
        Official FindByName(string officialName);
        Official Update(Official official);
        void Delete(Official official);
    }

    [ContractClassFor(typeof(IOfficialRepository))]
    public abstract class OfficialRepositoryContracts : IOfficialRepository
    {
        public void Dispose()
        {
            throw new NotImplementedException();
        }

        public IEnumerator<Official> GetEnumerator()
        {
            throw new NotImplementedException();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        public Expression Expression
        {
            get
            {
                throw new NotImplementedException();
            }
        }

        public Type ElementType
        {
            get
            {
                throw new NotImplementedException();
            }
        }

        public IQueryProvider Provider
        {
            get
            {
                throw new NotImplementedException();
            }
        }

        public Official Create(string name)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(name));
            Contract.Ensures(Contract.Result<Official>().OfficialId > 0);
            return null;
        }

        public Official Create(string name, string number)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(name));
            Contract.Requires(!string.IsNullOrWhiteSpace(number));
            Contract.Requires(number.Length > 0 && number.Length <= 4);
            Contract.Requires(Regex.IsMatch(number, "[a-zA-Z0-9]+"));
            return null;
        }

        public Official FindById(int officialId)
        {
            Contract.Requires(officialId > 0);
            return null;
        }

        public Official FindByName(string officialName)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(officialName));
            return null;
        }

        public Official Update(Official official)
        {
            Contract.Requires(official != null);
            Contract.Requires(official.OfficialId > 0);
            return null;
        }

        public void Delete(Official official)
        {
            Contract.Requires(official != null);
            Contract.Requires(official.OfficialId > 0);
            return;
        }
    }
}
